function GetQueryString(name) {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    let r = window.location.search.substring(1).match(reg); //获取url中"?"符后的字符串并正则匹配
    let context = "";
    if (r != null)
        context = decodeURIComponent(r[2]);
    reg = null;
    r = null;
    return context == null || context == "" || context == "undefined" ? "" : context;
}
/**
 * 判断是否是微信
 * @returns {boolean}
 */
function isWeChat(){
    let ua = window.navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i) == 'micromessenger'){
        return true;
    }else{
        return false;
    }
}

/**
 * 判断是否是微信小程序
 * @returns {boolean}
 */
function isWeChatXcx(){
    let ua = window.__wxjs_environment;
    if(ua === 'miniprogram'){
        return true;
    }else{
        return false;
    }
}
setTimeout(function (){
    if(isWeChat()){
        let activity_id = GetQueryString('activity_id');
        let flag = GetQueryString('flag');
        let field = {
            activity_id: activity_id,
            flag: flag,
        };
        axiosReq({
            url: setter.request.domainName + '/api/Index/getWeChatShare' //实际使用请改成服务端真实接口
            , params: field
            , method: 'GET'
            , loading: false // 是否开启加载框
            , is_message: false
            , done: function (res) {
                let data = res.data;
                wx.config({
                    debug:false,
                    appId: data.appid,
                    timestamp: data.timestamp,
                    nonceStr: data.noncestr,
                    signature: data.signature,
                    jsApiList:[
                        'onMenuShareTimeline','onMenuShareAppMessage','showMenuItems','hideOptionMenu'
                    ]
                });
                let imgUrl = cdnUrlFilter(data.imgUrl, true);
                let shareData = {
                    title: data.title,
                    desc: data.desc,
                    link: data.url,
                    imgUrl: imgUrl,
                    success: function(){
                    },
                    cancel: function(){
                    }
                };
                wx.ready(function () {
                    wx.onMenuShareTimeline(shareData);
                    wx.onMenuShareAppMessage(shareData);
                    wx.hideOptionMenu();
                    wx.showMenuItems({menuList: ['menuItem:share:appMessage','menuItem:share:timeline']});
                    document.getElementById('music').play()
                });
                if(isWeChatXcx()){
                    wx.miniProgram.postMessage({
                        data: {
                            title: data.title,
                        }
                    });
                }
            }
        })
    }
}, 800)